﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bzure.Common.Core;
using Bzure.Common.Data;

namespace Bzure.Apps.Security
{
    [Serializable]
    public class UserRoleMap : Entity
    {
        public UserRoleMap()
        {
            this.UserID = string.Empty;
            this.RoleID = string.Empty;
        }
        /// <summary>
        /// 用户角色对应表
        /// </summary>
        /// <summary>
        /// 用户ID
        /// </summary>
        public String UserID { set; get; }
        /// <summary>
        /// 角色ID
        /// </summary>
        public String RoleID { set; get; }
    }
    /// <summary>
    /// 资源
    /// </summary>
    [Serializable]
    public class DroitResource : Entity
    {
        public DroitResource(string ResourceID)
        {
            this.ResourceID = ResourceID;
        }
        public string ResourceID { get; private set; }
        /// <summary>
        /// 资源名称
        /// </summary>
        public string ResourceName { get; set; }
        /// <summary>
        /// 角色ID
        /// </summary>
        public string RoleID { get; set; }
        /// <summary>
        /// 权限值
        /// </summary>
        public int RightValue { get; set; }
        /// <summary>
        /// 资源状态
        /// </summary>
        public int State { get; set; }
    }
    /// <summary>
    /// 用户绑定
    /// </summary>
    [Serializable]
    public class UserBind : Entity, IPostEntity
    {
        /// <summary>
        /// 绑定ID
        /// </summary>
        public string ID { get; set; }
        /// <summary>
        /// 用户ID
        /// </summary>
        public string UserID { get; set; }
        /// <summary>
        /// 绑定ID
        /// </summary>
        public string BindID { get; set; }
        /// <summary>
        /// 合作绑定方
        /// </summary>
        public string BindProvider { get; set; }
        public EntityPostRequest ToUpdateRequest()
        {
            EntityPostRequest request;
            if (this.IsPersisted())
            {
                request = new EntityPostRequest(EntityPostRequest.EntityPostMethod.Update)
                {
                    Entity = this
                };
                request.AppendConditionMap(this.ID, () => this.ID);
            }
            else
            {
                request = new EntityPostRequest(EntityPostRequest.EntityPostMethod.Create)
                {
                    Entity = this
                };
                request.AppendFieldMap(this.ID, () => this.ID);
            }
            request.AppendFieldMap(this.UserID, () => this.UserID);
            request.AppendFieldMap(this.BindID, () => this.BindID);
            request.AppendFieldMap(this.BindProvider, () => this.BindProvider);
            return request;
        }
        public EntityPostRequest ToDeleteRequest()
        {
            EntityPostRequest post = new EntityPostRequest(EntityPostRequest.EntityPostMethod.Delete)
            {
                Entity = this
            };
            post.AppendConditionMap(this.ID, () => this.ID);
            return post;
        }
    }
}
